package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.FileManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: hippo
 */
@RestController
public class FileManageController {

    @Autowired
    private FileManageService fileManageService;

    @PostMapping("/upload")
    public JSONObject upload(@RequestParam("file") MultipartFile file) {
        return fileManageService.upload(file);
    }

    @PostMapping("/uploadCheck/{fieldName}")
    public JSONObject uploadCheck(@RequestParam("file") MultipartFile file, @PathVariable String fieldName) {
        return fileManageService.uploadCheck(file, fieldName);
    }

    @RequiresPermissions("fileManage:list")
    @PostMapping("/getFileManageList")
    public JSONObject getFileManageList(@RequestBody JSONObject data) {
        return fileManageService.getFileManageList(data);
    }

    @RequiresPermissions("fileManage:add")
    @PostMapping("/addFile")
    public JSONObject addFileManage(@RequestBody JSONObject data) {
        return fileManageService.addFile(data);
    }

    @RequiresPermissions("fileManage:delete")
    @DeleteMapping("/deleteFile/{id}")
    public JSONObject deleteFileManage(@PathVariable String id) {
        return fileManageService.deleteFile(id);
    }


}
